<script setup>
import { articleDelListService, articleGetChannelListService } from '@/api/article'
import {ref,provide} from 'vue'
import {Edit,Delete} from '@element-plus/icons-vue'
import EditChannelsBox from './components/EditChannelsBox.vue'
import { ElMessage,ElMessageBox } from 'element-plus'

const articleChannels = ref([])
// 加载动画
const isLoading = ref(false)

// 发送请求获取文章分类数据
const getChannels = async ()=>{
  isLoading.value = true
  const res = await articleGetChannelListService()
  articleChannels.value = res.data.data
  isLoading.value = false
}
provide('getChannels',getChannels)
getChannels()


// 编辑文章分类按钮
const dialog = ref(null)
const handleEdit = (row)=>{
  // row当前点击行数据对象
  // 打开弹窗,回显当前点击的数据
 dialog.value.open(row)

}
// 删除文章分类按钮
const handleDelete = async (row)=>{
  await ElMessageBox.confirm('你确认删除该分类信息吗？', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  console.log(row.id)
  await articleDelListService(row.id)
  ElMessage({ type: 'success', message: '删除成功' })
  console.log(row.id)
  getChannels()
}
// 添加文章分类
const addChannel = ()=>{
  // 打开弹窗,获取数据
  dialog.value.open({})
  // 发送添加请求
}
</script>
<template>
  <page-container title="文章分类">
    <template #extra>
      <el-button type="primary" @click="addChannel">添加分类</el-button>
    </template>
    <el-table v-loading="isLoading" :data="articleChannels" style="width: 100%" >
      <el-table-column type="index" label="序号" width="100"/>
      <el-table-column prop="cate_name" label="分类名称"/>
      <el-table-column prop="cate_alias" label="分类别名"/>
      <el-table-column  label="操作" width="100">
        <template #default="{row,$index }" >
          <el-button type="primary" :icon="Edit" circle plain @click="handleEdit(row,$index)" />
          <el-button type="danger" :icon="Delete" circle plain @click="handleDelete(row,$index)" />
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据"></el-empty>
      </template>
    </el-table>
    <edit-channels-box ref="dialog"></edit-channels-box>
  </page-container>
</template>

